package com.leyou.cart.listener;

import com.leyou.cart.service.CartService;
import com.leyou.common.constants.MQConstants;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class CartListener {

    @Autowired
    private CartService cartService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = MQConstants.Queue.CART_ORDER_FORMED, durable = "true"),
            exchange = @Exchange(name = MQConstants.Exchange.ORDER_EXCHANGE_NAME, type = ExchangeTypes.TOPIC),
            key = MQConstants.RoutingKey.CART_DELED_KEY
    ))
    public void delCart(Long id){
        cartService.delCart(id);
    }
}
